------------------------------------------------------------------------------------------------------------------------------------ name: log: C:\Projects\Analysis\Calendar tutorial\Stata\Example6.log log type: text opened on: 31 Aug 2017, 00:30:21 . * DHS Calendar Tutorial - Example 6 . * Contraceptive prevalence rate (CPR) month by month over time . . * download the model dataset for individual women's recode: "ZZIR62FL.DTA" . * the model datasets are available at http://dhsprogram.com/data/download-model-datasets.cfm . . * change to a working directory where the data are stored . * or add the full path to the 'use' command below . cd "C:\Data\DHS_model" C:\Data\DHS_model . . * open the dataset to use, selecting just the variables we are going to use . use caseid vcal_1 v000 v005 v007 v008 v011 v018 v021 v023 using "ZZIR62FL.DTA", clear . . . * Step 6.1 . * loop through calendar creating separate variables for each month . * total length of calendar to loop over including leading blanks (80) . local vcal_len = strlen(vcal_1[1]) . forvalues i = 1/`vcal_len' { 2. gen str1 method`i' = substr(vcal_1,`i',1) 3. } . . . * Step 6.2 . * drop calendar string variable as we don't need it further . drop vcal_1 . . * reshape the data file into a file where the month is the unit of analysis . reshape long method, i(caseid) j(i) (note: j = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 4 > 4 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80) Data wide -> long ----------------------------------------------------------------------------- Number of obs. 8348 -> 667840 Number of variables 89 -> 11 j variable (80 values) -> i xij variables: method1 method2 ... method80 -> method ----------------------------------------------------------------------------- . . . * Step 6.3 . * find the position of the earliest date of interview (the maximum value of v018) . egen v018_max = max(v018) . . * drop cases outside of the five years preceding the earliest interview . * months 0-59 before the earliest interview date . keep if inrange(i,v018_max,v018_max+59) (166,960 observations deleted) . . . * Step 6.4 . * calculate age in months for each month in the calendar . gen agem = (v008 - v011) - (i - v018) . . * calculate century month code for each month . gen cmctime = v008 - (i - v018) . label variable cmctime "Century month code" . . * create variable for use of any method as a 0/100 variable . gen usingany = !inlist(method, "0","B","P","T") * 100 . label variable usingany "Using any method" . label def usingany 0 "Not using" 100 "Using a method" . label val usingany usingany . . . * Step 6.5 . * compute weight variable . gen wt=v005/1000000 . . * simply tabulate CPR for each month . tab cmctime usingany [iw=wt] if inrange(agem,180,539), row nofreq Century | Using any method month code | Not using Using a m | Total -----------+----------------------+---------- 1327 | 93.17 6.83 | 100.00 1328 | 93.09 6.91 | 100.00 1329 | 93.00 7.00 | 100.00 1330 | 92.84 7.16 | 100.00 1331 | 92.75 7.25 | 100.00 1332 | 92.43 7.57 | 100.00 1333 | 92.21 7.79 | 100.00 1334 | 92.08 7.92 | 100.00 1335 | 92.00 8.00 | 100.00 1336 | 91.70 8.30 | 100.00 1337 | 91.64 8.36 | 100.00 1338 | 91.29 8.71 | 100.00 1339 | 90.71 9.29 | 100.00 1340 | 90.45 9.55 | 100.00 1341 | 90.38 9.62 | 100.00 1342 | 90.34 9.66 | 100.00 1343 | 90.31 9.69 | 100.00 1344 | 90.18 9.82 | 100.00 1345 | 89.86 10.14 | 100.00 1346 | 89.53 10.47 | 100.00 1347 | 89.27 10.73 | 100.00 1348 | 89.02 10.98 | 100.00 1349 | 88.56 11.44 | 100.00 1350 | 88.11 11.89 | 100.00 1351 | 87.85 12.15 | 100.00 1352 | 87.60 12.40 | 100.00 1353 | 87.47 12.53 | 100.00 1354 | 87.38 12.62 | 100.00 1355 | 87.41 12.59 | 100.00 1356 | 87.28 12.72 | 100.00 1357 | 86.97 13.03 | 100.00 1358 | 86.70 13.30 | 100.00 1359 | 86.25 13.75 | 100.00 1360 | 85.69 14.31 | 100.00 1361 | 85.46 14.54 | 100.00 1362 | 85.02 14.98 | 100.00 1363 | 84.74 15.26 | 100.00 1364 | 84.51 15.49 | 100.00 1365 | 84.33 15.67 | 100.00 1366 | 84.21 15.79 | 100.00 1367 | 84.24 15.76 | 100.00 1368 | 84.23 15.77 | 100.00 1369 | 83.57 16.43 | 100.00 1370 | 82.95 17.05 | 100.00 1371 | 82.43 17.57 | 100.00 1372 | 81.94 18.06 | 100.00 1373 | 81.81 18.19 | 100.00 1374 | 81.22 18.78 | 100.00 1375 | 81.18 18.82 | 100.00 1376 | 80.74 19.26 | 100.00 1377 | 80.42 19.58 | 100.00 1378 | 80.25 19.75 | 100.00 1379 | 79.71 20.29 | 100.00 1380 | 79.18 20.82 | 100.00 1381 | 78.48 21.52 | 100.00 1382 | 78.23 21.77 | 100.00 1383 | 77.76 22.24 | 100.00 1384 | 77.08 22.92 | 100.00 1385 | 76.37 23.63 | 100.00 1386 | 75.77 24.23 | 100.00 -----------+----------------------+---------- Total | 85.94 14.06 | 100.00 . . * set up the svy paramters and calculate the mean of usingany (which is the CPR) . svyset v021 [pweight=wt], strata(v023) pweight: wt VCE: linearized Single unit: missing Strata 1: v023 SU 1: v021 FPC 1: . . * tabulate CPR for women 15-44 . svy, subpop(if inrange(agem,180,539)): mean usingany, over(cmctime) nolegend (running mean on estimation sample) Survey: Mean estimation Number of strata = 8 Number of obs = 500,880 Number of PSUs = 217 Population size = 500,879.98 Subpop. no. obs = 415,066 Subpop. size = 419,215.66 Design df = 209 -------------------------------------------------------------- | Linearized Over | Mean Std. Err. [95% Conf. Interval] -------------+------------------------------------------------ usingany | 1327 | 6.826301 1.394903 4.076417 9.576184 1328 | 6.907226 1.39015 4.166713 9.64774 1329 | 7.003087 1.384522 4.273668 9.732506 1330 | 7.162718 1.362503 4.476707 9.848729 1331 | 7.250781 1.354845 4.579868 9.921695 1332 | 7.57439 1.433646 4.74813 10.40065 1333 | 7.791406 1.518362 4.798139 10.78467 1334 | 7.918431 1.523505 4.915023 10.92184 1335 | 7.995632 1.42497 5.186475 10.80479 1336 | 8.304927 1.505767 5.336489 11.27336 1337 | 8.360027 1.47329 5.455613 11.26444 1338 | 8.705975 1.619501 5.513323 11.89863 1339 | 9.293078 1.772632 5.798547 12.78761 1340 | 9.548267 1.855908 5.889567 13.20697 1341 | 9.616516 1.757516 6.151786 13.08125 1342 | 9.659246 1.742195 6.224719 13.09377 1343 | 9.688056 1.727471 6.282555 13.09356 1344 | 9.818077 1.722848 6.42169 13.21446 1345 | 10.14429 1.797486 6.600764 13.68782 1346 | 10.47487 1.689904 7.14343 13.80632 1347 | 10.73104 1.72581 7.328816 14.13327 1348 | 10.97644 1.682512 7.659574 14.29331 1349 | 11.44304 1.654197 8.181986 14.70409 1350 | 11.88802 1.647213 8.640737 15.1353 1351 | 12.15204 1.712481 8.776091 15.52799 1352 | 12.40302 1.781062 8.891871 15.91417 1353 | 12.52892 1.784517 9.010963 16.04688 1354 | 12.6182 1.778422 9.112258 16.12415 1355 | 12.58572 1.778742 9.079139 16.09229 1356 | 12.71764 1.765487 9.237193 16.19808 1357 | 13.03124 1.666866 9.745213 16.31726 1358 | 13.29739 1.752256 9.843025 16.75175 1359 | 13.74868 1.80117 10.19788 17.29947 1360 | 14.31233 1.855829 10.65378 17.97087 1361 | 14.5398 1.84365 10.90527 18.17433 1362 | 14.97648 1.899527 11.23179 18.72117 1363 | 15.25645 1.865809 11.57823 18.93466 1364 | 15.49366 1.745618 12.05238 18.93493 1365 | 15.66688 1.722182 12.27181 19.06196 1366 | 15.78676 1.711957 12.41184 19.16168 1367 | 15.7607 1.705844 12.39784 19.12357 1368 | 15.76813 1.70541 12.40612 19.13014 1369 | 16.43327 1.772216 12.93956 19.92698 1370 | 17.04896 2.00703 13.09234 21.00558 1371 | 17.57024 2.224489 13.18493 21.95555 1372 | 18.06329 2.285629 13.55745 22.56913 1373 | 18.1907 2.190652 13.87209 22.50931 1374 | 18.7826 2.14883 14.54644 23.01876 1375 | 18.82163 2.14552 14.592 23.05127 1376 | 19.26218 2.130525 15.06211 23.46226 1377 | 19.58263 2.042189 15.5567 23.60856 1378 | 19.7548 2.11941 15.57664 23.93296 1379 | 20.29312 2.085764 16.18129 24.40496 1380 | 20.82156 2.132107 16.61836 25.02475 1381 | 21.52466 2.016138 17.55009 25.49923 1382 | 21.76771 2.016651 17.79212 25.74329 1383 | 22.24158 1.91256 18.4712 26.01196 1384 | 22.91808 1.886763 19.19855 26.6376 1385 | 23.63029 1.83193 20.01886 27.24172 1386 | 24.22737 1.80001 20.67887 27.77588 -------------------------------------------------------------- . end of do-file name: log: C:\Projects\Analysis\Calendar tutorial\Stata\Example6.log log type: text closed on: 31 Aug 2017, 00:30:35 ------------------------------------------------------------------------------------------------------------------------------------